//
//  HistoryViewController.m
//  SouhuTV
//
//  Created by 肖野 on 15/6/10.
//  Copyright (c) 2015年 Mike. All rights reserved.
//

#import "HistoryViewController.h"
#import "XYMainFunction.h"

@interface HistoryViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>


@property (nonatomic, retain) UICollectionView* collectionView;

@property (nonatomic, retain) NSMutableArray* arr;

@end

@implementation HistoryViewController


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.title = @"播放历史";
    self.arr = [NSMutableArray arrayWithArray:[HistoryUserDefault getHistoryArrayData]];
    
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake((self.view.frame.size.width - 15) / 3 , self.view.frame.size.width / 3 * 1.4 + 25);
    layout.minimumInteritemSpacing = 5;
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height ) collectionViewLayout:layout];
    _collectionView.backgroundColor = [UIColor whiteColor];
    _collectionView.dataSource = self;
    _collectionView.delegate = self;
    
    //注册cell
    [_collectionView registerClass:[HomePageCollectionCell class] forCellWithReuseIdentifier:@"CELL"];
    
    [self.view addSubview:_collectionView];
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    
}

//- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
//{
///}
//
//- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
//{
//    HomePageCollectionCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
//    NSArray* arr = [NSArray arrayWithObjects:[[NSUserDefaults standardUserDefaults] objectForKey:@"movie"], nil];
//
//    cell.baseInfo = [MovieBaseInfo movieBaseInfoWithDictionary:arr[indexPath.row]];
//    return cell;
//}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.arr.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    HomePageCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CELL" forIndexPath:indexPath];
    
    
    cell.baseInfo = [MovieBaseInfo movieBaseInfoWithDictionary:self.arr[indexPath.item]];
    NSLog(@"img ====== %@", [MovieBaseInfo movieBaseInfoWithDictionary:self.arr[indexPath.item]].img);
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    MovieBaseInfo* movie = [MovieBaseInfo movieBaseInfoWithDictionary:self.arr[indexPath.item]];
    MovieDetailViewController* movieDetail = [[MovieDetailViewController alloc] init];
    movieDetail.ID = movie.ID;
    [self.navigationController pushViewController:movieDetail animated:YES];
    
}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
